def function-Name(self,argument,...,*argument): Statements ---------- return value
class Account: def setData(self,an,bal): self.accno=an self.balance=bal def interest(self,r,*years): print("Balance:",self.balance) print("Rate:",r) for n in years: si=self.balance*r*n/100 print("Interest for",n,"years is",si) a=Account( ) a.setData(4117,25000) a.interest(10.25,1,2,3,5,10)
Balance: 25000 Rate: 10.25 Interest for 1 years is 2562.5 Interest for 2 years is 5125.0 Interest for 3 years is 7687.5 Interest for 5 years is 12812.5 Interest for 10 years is 25625.0
class Student: def setData(self,rn,nm,br,*mks): self.rollno=rn self.name=nm self.branch=br self.marks=mks def showData(self): print("RollNo is",self.rollno) print("Name is",self.name) print("Branch is",self.branch) def total(self): t=0 for mk in self.marks: t=t+mk print("Total is",t) def result(self): for mk in self.marks: if mk<40: print("Result is Fail") break else: print("Result is Pass") a=Student() a.setData(4117,"Amit Jain","CSE-1",56,67,34,78,87) a.showData() a.total() a.result()
RollNo is 4117 Name is Amit Jain Branch is CSE-1 Total is 312 Result is Fail